home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2169 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.4 KB

  1. Path: ns.cs.hku.hk!sdlee
  2. From: sdlee@cs.hku.hk (Lee Sau Dan ~{@nJX6X~})
  3. Newsgroups: hku.open-forum,hk.comp.pc,comp.lang.c++,comp.lang.pascal.misc
  4. Subject: Re: Is Pascal worth to learn? Can it help me to get a job?
  5. Date: 16 Jan 1996 02:50:19 GMT
  6. Organization: Computer Science Dept, University of Hong Kong
  7. Message-ID: <SDLEE.96Jan16105019@champion.cs.hku.hk>
  8. References: <30f2adf8.7810115@news.hku.hk> <DL2tFM.7DJ@hkuxb.hku.hk>
  9.     <4dcrl0$7mo_001@news.hku.hk> <SDLEE.96Jan15161338@champion.cs.hku.hk>
  10.     <4devt9$844_001@news.hku.hk>
  11. NNTP-Posting-Host: champion.cs.hku.hk
  12. In-reply-to: kong@hkusua.hku.hk's message of Tue, 16 Jan 1996 01:44:09 GMT
  13.  
  14. In article <4devt9$844_001@news.hku.hk> kong@hkusua.hku.hk (someone) writes:
  15.  
  16.     >>    I do agree using the swapping method I mentioned is not a
  17.     >> common practice (and I myself never have to do it). But it does
  18.     >> demonstrate the power of a language.
  19.  
  20. Is that really the power of a computer language, or just the power of
  21. some mathematical tricks?  How much is it faster?  Mind you that
  22. optimizing compilers are able to allocate a temp. variable in a
  23. register for this swapping purpose.  If it just makes the code
  24. more difficult to understand, then think twice before you write it.
  25.  
  26.  
  27.     >>    Bit-vectors ARE required in many cases, and I strongly
  28.     >> disagree that they are difficult to debug or maintain. There
  29.     >> are cases when there will be matrixes with hundreds or at times
  30.     >> millions of elements, each containing just a few boolean
  31.     >> values. It will be much easier to debug and maintain the code
  32.     >> by using bit-vectors and use masks defined as constants to set
  33.     >> or get the required bits. Not to mention the memories saved
  34.     >> compared to using arrays of booleans.
  35.  
  36. Well... Bit-vectors are good only if the word length is always the
  37. same on all machines.  The size of an 'int' can be different on
  38. different platforms and compilers.  For example, the 'int' in
  39. Borland C is 16-bit long, while that in GCC is 32-bit long.
  40. Writing portable programs using bit-vectors is a headache.  It is
  41. not just a simple task of applying masks.
  42.  
  43. Yes, I agree that memory can be saved by using bit vectors.  However,
  44. manipulations on bit vectors are usually not as fast as manipulations
  45. on integer.  This is because intergers are more native to many processors
  46. than single bits.  That's why many people (even assembler programmers
  47. and compilers) simply use an 'int' for a boolean variable.  They are
  48. faster and memory is "cheap".  Unless you intend to do operations
  49. on several bits at a time, using bit vectors won't save you much time.
  50.  
  51. Of course, if your boolean array is long, you may want to optimize
  52. the memory usage by using bit vectors.  However, there is also
  53. something know as "packed array" in Pascal!
  54.  
  55.  
  56.     >>    Er.. right. While I said that in my post I was responding to
  57.     >> the original poster's claim that Pascal can do everything other
  58.     >> language can do.
  59.  
  60. That's true.  Pascal can do everything other languages can do.  I'm
  61. not talking about machine specific operations (e.g. controlling DMA
  62. and IRQ), of course.  In the most extreme case, you can write a C
  63. interpreter in Pascal.  Then, for any C program you write, the
  64. interpreter (a Pascal program) can do exactly the same things as your
  65. C program.
  66.  
  67.  
  68.     >> The ability to cast a pointer to something else is a two side
  69.     >> sword. A good programmer can make use of it wisely. Lousy
  70.     >> programmers make pointer errors out of it.
  71.  
  72. That's a reason why Pascal is easier for beginners than C.  Do you
  73. remember the nightmares with C strings when you were learning C?
  74. Pointers in C is flexible.  It is a powerful tool if you can manage to
  75. use it properly.  For beginners, it is often the killer of their
  76. programs!  An an analog, a knife is a useful tool.  You can use it to
  77. cut food.  However, if kids use it improperly, it hurts them.
  78.  
  79.  
  80.     >>    Out-of-bound array references can happen in Pascal, if you
  81.     >> turn-off your run-time array bound checking.
  82.  
  83. Do all Pascal compilers offer this option?  Even if a compiler supports
  84. such an option, it should be disabled by default.
  85.  
  86.  
  87.     >> Again, pointers arithmetic in C is a two side sword.
  88.  
  89. Agree!  Whenever something is powerful enough to be useful, it is also
  90. powerful enough to be harmful.  Pencils are not sharpened at both ends.
  91.  
  92.  
  93.  
  94. --
  95. Lee Sau Dan
  96.  
  97. -------------------------------------------------------------------------------
  98. URL: http://www.cs.hku.hk/~sdlee
  99. e-mail: sdlee@cs.hku.hk
  100.